Skip to content

Invoke-PkProcessWithTimeout starts nothing during an abort or cancel - #96

Merged
HalRiveria-Bot merged 5 commits into
mainfrom
fix/with-timeout-during-abort
Dec 1, 2026
Merged

HalRiveria-Bot merged 5 commits into
mainfrom
fix/with-timeout-during-abort

Conversation

@HalRiveria-Bot

Copy link
Copy Markdown
Collaborator

Invoke-PkProcessWithTimeout started its program even when an abort or cancel was already in force. It only looked for one after its first 200 ms wait, so a program that finished sooner ran to the end and returned normally, and a slower one ran for about 200 ms before it was killed. The README says it throws when the run is aborted, and the batch starts nothing then.

  • It makes the same check right before starting the program, and throws "'x' wasn't started because the run is being aborted". -IgnoreAbort skips it, as it does the one in the loop. A bad argument is still reported first.
  • The README and the function's help say so.

This changes behavior: a quick program run during an abort without -IgnoreAbort used to work by luck. That includes a cleanup program in -JobAbortCleanup, and one run after an aborted Invoke-PkRun returns, since an abort stays in force until Reset-PkAbortState. Those need -IgnoreAbort now.

Tests

Section S runs a program that writes a file, so a run leaves a trace: during an abort, and in a worker whose run is canceled.

  • On the old code, 5.1 and 7 both fail: during an abort, a quick program isn't started and in a worker whose run is canceled, a quick program isn't started, except with -IgnoreAbort (nothing thrown).
  • With the fix, both pass, and -IgnoreAbort still runs the program.
  • Full harness: 709 passed on Windows PowerShell 5.1 and 709 passed on PowerShell 7.6.2, no skips.

🤖 Generated with Claude Code

HalRiveria and others added 5 commits December 1, 2026 16:12
Two of the batch's own closures called Complete-PkProcess and Write-PkMessage
by name. A .GetNewClosure() block only sees global functions, so a batch failed
with "'Complete-PkProcess' is not recognized" when the kit was loaded for one
module only. They're captured up front now, like the private helpers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A worker given the function (-SharedFunctionNames takes it) could set a handler
made in its own runspace, which the main thread then ran for every message.
Running another runspace's scriptblock can hang or crash PowerShell.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
It only looked for an abort after its first 200 ms wait, so a program that
finished sooner ran to the end and returned normally, and a slower one ran for
about 200 ms before it was killed. It now throws before starting the program,
unless -IgnoreAbort is given.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@HalRiveria-Bot
HalRiveria-Bot merged commit ebbd4a9 into main Dec 1, 2026
2 checks passed
@HalRiveria-Bot
HalRiveria-Bot deleted the fix/with-timeout-during-abort branch December 1, 2026 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants